package com.example.demo.controller;

import com.example.demo.entity.Movie;
import com.example.demo.entity.User;
import com.example.demo.mapper.MovieMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class MovieController {

    @Autowired
    private MovieMapper movieMapper;

    //根据前端传的电影id返回该部电影的所有信息
    @RequestMapping("/seat_choose")
    public Object seat_choose(Integer movieId, HttpServletRequest req) {
        int id = movieId;
        HttpSession session = req.getSession(false);
        User user = (User) session.getAttribute("user");
        List<Movie> list = movieMapper.film_sessions(id);
        for (Movie movie : list) {
            movie.setPhoneNum(user.getUsername());
        }
        return list;
    }

    //根据前端传的电影id返回该部电影的所有信息
    @RequestMapping("/film_sessions")
    public Object film_sessions(Integer movieId) {
        return movieMapper.film_sessions(movieId);
    }
}
